//WS2812氛围灯呼吸效果
#include <Adafruit_NeoPixel.h>
#define BLINKER_PRINT Serial

//RGB灯
#define PIN 15  //  DIN PIN (GPIO15, D8)
#define NUMPIXELS 10  // Number of you led
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int light = 0; //亮度的值
int fadeAmount = 1; //亮度的增量
int r = 255,g = 255, b =255;
int flag = 0; //改变颜色

//控制rgb灯
void SET_RGB(int R,int G,int B,int bright)
{
    for (uint16_t i = 0; i < NUMPIXELS; i++) //把灯条变色
    {
        pixels.setPixelColor(i,R,G,B);
    }
    pixels.setBrightness(bright);//亮度
    pixels.show();    //送出显示
}

//呼吸灯
void hxled()
{
	SET_RGB(r,g,b,light); 
	light += fadeAmount;
	if(light == 0 || light == 255)
	{
		fadeAmount = -fadeAmount;
    flag++;
	}
  if(flag == 2)
  {
    //随机产生颜色值
    r = random(255);
    g = random(255);
    b = random(255);
    flag = 0;
  }
}


void setup() {
    // 初始化串口
    Serial.begin(115200);
    pixels.begin();//WS2812初始化
    pixels.show();    
}

void loop() {
	
	hxled();
	delay(15); //15ms   
}
